<?php

/**
 *用户信息列表
 * User: huy
 * Date: 2016/7/6
 * Time: 17:43
 */
class UserinfoControl extends Control{
    private $time1    = '2016-07-20 00:00:00';   //开始
    private $time2    = '2016-08-01 00:00:00';   //中间投票时间
    private $time3    = '2016-08-31 23:59:59';   //结束
    private $hcoin    = 0;
    private $gamecoin = 5000;//投票每一票消耗的游戏币5000
    private $limit    = 10;   //每天最多投10票
    private $level    = 30;//参加活动的等级限制

    //构造函数
    function __construct(){
        parent::__construct();
        $this->actName = '新炫舞宝贝评选';
        load_config('commonMain/onload');
        $this->zone_arr = get_dmz_game_zone();
        load_model(ACT_NAME . '/main');   //自己的main.mod
        $this->model = new MainModel();
        //重新设置活动时间（用于外网、预发布环境）
        if(file_exists(APPLICATION_ROOT . '/config/basic.cfg.php')){
            //include文件的路径，$BasicCFG就存下了.php return 的数组
            $BasicCFG = include_once APPLICATION_ROOT . '/config/basic.cfg.php';
            if(!empty($BasicCFG[YEAR][ACT]['time1']) && !empty($BasicCFG[YEAR][ACT]['time2']) && !empty($BasicCFG[YEAR][ACT]['time3']) && !empty($BasicCFG[YEAR][ACT]['level']) && !empty($BasicCFG[YEAR][ACT]['gamecoin']) && !empty($BasicCFG[YEAR][ACT]['money'])){
                $this->time1    = $BasicCFG[YEAR][ACT]['time1'];
                $this->time2    = $BasicCFG[YEAR][ACT]['time2'];
                $this->time3    = $BasicCFG[YEAR][ACT]['time3'];
                $this->level    = $BasicCFG[YEAR][ACT]['level'];
                $this->gamecoin = $BasicCFG[YEAR][ACT]['gamecoin'];
                $this->money    = $BasicCFG[YEAR][ACT]['money'];
            }
        }
    }

    //用户信息页
    public function userinfo($uin, $zone_arr){

        $list = $this->model->get_item('bbpx2016_userinfo', '*', " uin={$uin}  limit 1");

        if(empty($list)){
            //没有报名，查看我的信息，跳转到报名页面
            header('Location:http://act.xx5.com/2016/bbpx2016/index.php?a=sign');
            exit;
        }                                          //xrzx_userinfo_copy
        $list_old          = $this->model->get_item('bbpx2016_userinfo', '*', " uin={$uin}  limit 1");
        $row               = $list[0];
        $row['status_old'] = $list_old[0]['status'];
        $row['brand']      = htmlspecialchars($row['brand']);   //把预定义的字符转换为html实体

        if(!empty($row)){
            $row['zone_id'] = $zone_arr[$row['zone_id']];
        }

        //ret  用户的个人信息，无论审核状态是什么，都显示个人信息
        $view['ret'] = $row;
        //给当前的用户送玫瑰的   用户数num     money_id>0  说明是送玫瑰  花费51点 投票的
        if(5 == $row['status']){    //审核通过
            /**1.显示给我投票最多的前10个玩家
             * type=1:所有投票前10   type=2:送玫瑰前10
             * get_help:按照投票票数取前10个   list给我投票最多的前10个玩家
             */
            $list = $this->model->get_help($uin, $type = 1);     //所有投票前10
            if(!empty($list)){
                foreach($list as &$it){
                    $it['zone_id'] = $zone_arr[$it['zone_id']];  //获取大区名称
                }
            }
            $view['list'] = $list;
            //2.最多送玫瑰的10个玩家
            //money_id>0说明是送玫瑰的
            $apple_list = $this->model->get_help($uin, $type = 2);
            if(!empty($apple_list)){
                foreach($apple_list as &$it){
                    $it['zone_id'] = $zone_arr[$it['zone_id']];  //获取大区名称
                }
            }
            $view['apple_list'] = $apple_list;
            //end of apple_list送玫瑰前10个
        }
        load_view(ACT_NAME . '/userinfo', $view);
    }
}